<?php
/**
 * Created by PhpStorm.
 * User: wumengmeng <wu_mengmeng@foxmail.com>
 * Date: 2019/4/26 0026
 * Time: 14:35
 */

namespace HiCommon\Service;

use Illuminate\Support\Facades\Cache;

class MenuService extends BaseService
{
    public function menu_tree_html($arr_permission)
    {
        $arr_menu_permission = collect($arr_permission)
            ->where('is_menu', 1)
            ->where('status', 1)
            ->sortBy('sort')
            ->values()
            ->all();
        //处理权限菜单数据-转为菜单树
        $arr_menu_data = make_tree($arr_menu_permission);
        $arr_menu_html = tree_menu_html($arr_menu_data);
        return $arr_menu_html;
    }

    /*web管理后台菜单*/
    public function api_menu_admin($n_uid)
    {
        //admin和shop_check、shop_check_app、shop_repair、shop_repair_app
        $arr_permission = cache_user_permissions_for_admin($n_uid);
        return self::menu_tree_html($arr_permission);
    }

    /*商户后台菜单*/
    public function api_menu_shop($n_uid)
    {
        $arr_permission = cache_user_permissions_for_shop($n_uid);
        return self::menu_tree_html($arr_permission);
    }

    /*商户端APP菜单*/
    public function api_menu_shop_app($n_uid)
    {
        $arr_permission = cache_user_permissions_for_shop_app($n_uid);
        $arr_menu_permission = collect($arr_permission)
          ->where('status', 1)
          ->sortBy('sort')
          ->values()
          ->all();
        return $arr_menu_permission;
    }


}